<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP                #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE DeriveDataTypeable #-}</span><span class="hs-cpp">

#if __GLASGOW_HASKELL__ &gt;= 701
</span><span class="hs-pragma">{-# LANGUAGE Trustworthy        #-}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-8"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Module      :  Control.Concurrent.STM.TBQueue</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2012</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Portability :  non-portable (requires STM)</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- 'TBQueue' is a bounded version of 'TQueue'. The queue has a maximum</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- capacity set when it is created.  If the queue already contains the</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- maximum number of elements, then 'writeTBQueue' blocks until an</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- element is removed from the queue.</span><span>
</span><span id="line-22"></span><span class="hs-comment">--</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- The implementation is based on the traditional purely-functional</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- queue representation that uses two lists to obtain amortised /O(1)/</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- enqueue and dequeue operations.</span><span>
</span><span id="line-26"></span><span class="hs-comment">--</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- @since 2.4</span><span>
</span><span id="line-28"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-29"></span><span>
</span><span id="line-30"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Control.Concurrent.STM.TBQueue</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-31"></span><span>        </span><span class="annot"><span class="hs-comment">-- * TBQueue</span></span><span>
</span><span id="line-32"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier">TBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#newTBQueue"><span class="hs-identifier">newTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#newTBQueueIO"><span class="hs-identifier">newTBQueueIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-35"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#readTBQueue"><span class="hs-identifier">readTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#tryReadTBQueue"><span class="hs-identifier">tryReadTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-37"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#flushTBQueue"><span class="hs-identifier">flushTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#peekTBQueue"><span class="hs-identifier">peekTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#tryPeekTBQueue"><span class="hs-identifier">tryPeekTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#writeTBQueue"><span class="hs-identifier">writeTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#unGetTBQueue"><span class="hs-identifier">unGetTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#lengthTBQueue"><span class="hs-identifier">lengthTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-43"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#isEmptyTBQueue"><span class="hs-identifier">isEmptyTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-44"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#isFullTBQueue"><span class="hs-identifier">isFullTBQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Data.Typeable.html#"><span class="hs-identifier">Data.Typeable</span></a></span><span>   </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Typeable.Internal.html#Typeable"><span class="hs-identifier">Typeable</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/GHC.Conc.html#"><span class="hs-identifier">GHC.Conc</span></a></span><span>        </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier">STM</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier">TVar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier">newTVar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier">newTVarIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#orElse"><span class="hs-identifier">orElse</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-49"></span><span>                                  </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier">readTVar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier">retry</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier">writeTVar</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Numeric.Natural.html#"><span class="hs-identifier">Numeric.Natural</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">Natural</span></span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span>           </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span>         </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Text.Read.html#read"><span class="hs-identifier">read</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-comment">-- | 'TBQueue' is an abstract type representing a bounded FIFO channel.</span><span>
</span><span id="line-54"></span><span class="hs-comment">--</span><span>
</span><span id="line-55"></span><span class="hs-comment">-- @since 2.4</span><span>
</span><span id="line-56"></span><span class="hs-keyword">data</span><span> </span><span id="TBQueue"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-var">TBQueue</span></a></span></span><span> </span><span id="local-6989586621679036897"><span class="annot"><a href="#local-6989586621679036897"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-57"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span id="TBQueue"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-var">TBQueue</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Natural</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- CR:  read capacity</span><span>
</span><span id="line-58"></span><span>             </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679036897"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>     </span><span class="hs-comment">-- R:   elements waiting to be read</span><span>
</span><span id="line-59"></span><span>             </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Natural</span></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- CW:  write capacity</span><span>
</span><span id="line-60"></span><span>             </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679036897"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>     </span><span class="hs-comment">-- W:   elements written (head is most recent)</span><span>
</span><span id="line-61"></span><span>                            </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">Natural</span></span><span class="hs-special">)</span><span>      </span><span class="hs-comment">-- CAP: initial capacity</span><span>
</span><span id="line-62"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="annot"><a href="../../base/src/Data.Typeable.Internal.html#Typeable"><span class="hs-identifier hs-type">Typeable</span></a></span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span id="local-6989586621679036907"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679036837"><span class="annot"><span class="hs-identifier hs-type">Eq</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036907"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-65"></span><span>  </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036833"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036833"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679036832"><span class="annot"><span class="annottext">== :: TBQueue a -&gt; TBQueue a -&gt; Bool
</span><span class="hs-operator hs-var hs-var hs-var hs-var">==</span></span></span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036831"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036831"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036833"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; TVar Natural -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036831"><span class="hs-identifier hs-var">b</span></a></span></span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-comment">-- Total channel capacity remaining is CR + CW. Reads only need to</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- access CR, writes usually need to access only CW but sometimes need</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- CR.  So in the common case we avoid contention between CR and CW.</span><span>
</span><span id="line-70"></span><span class="hs-comment">--</span><span>
</span><span id="line-71"></span><span class="hs-comment">--   - when removing an element from R:</span><span>
</span><span id="line-72"></span><span class="hs-comment">--     CR := CR + 1</span><span>
</span><span id="line-73"></span><span class="hs-comment">--</span><span>
</span><span id="line-74"></span><span class="hs-comment">--   - when adding an element to W:</span><span>
</span><span id="line-75"></span><span class="hs-comment">--     if CW is non-zero</span><span>
</span><span id="line-76"></span><span class="hs-comment">--         then CW := CW - 1</span><span>
</span><span id="line-77"></span><span class="hs-comment">--         then if CR is non-zero</span><span>
</span><span id="line-78"></span><span class="hs-comment">--                 then CW := CR - 1; CR := 0</span><span>
</span><span id="line-79"></span><span class="hs-comment">--                 else **FULL**</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span><span class="hs-comment">-- | Builds and returns a new instance of 'TBQueue'.</span><span>
</span><span id="line-82"></span><span id="local-6989586621679036904"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#newTBQueue"><span class="hs-identifier hs-type">newTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Natural</span></span><span>   </span><span class="hs-comment">-- ^ maximum number of elements the queue can hold</span><span>
</span><span id="line-83"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036904"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-84"></span><span id="newTBQueue"><span class="annot"><span class="annottext">newTBQueue :: forall a. Natural -&gt; STM (TBQueue a)
</span><a href="Control.Concurrent.STM.TBQueue.html#newTBQueue"><span class="hs-identifier hs-var hs-var">newTBQueue</span></a></span></span><span> </span><span id="local-6989586621679036822"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036822"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-85"></span><span>  </span><span id="local-6989586621679036821"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036821"><span class="hs-identifier hs-var">read</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; STM (TVar [a])
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-86"></span><span>  </span><span id="local-6989586621679036820"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036820"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; STM (TVar [a])
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-87"></span><span>  </span><span id="local-6989586621679036819"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036819"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Natural -&gt; STM (TVar Natural)
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span>
</span><span id="line-88"></span><span>  </span><span id="local-6989586621679036818"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036818"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Natural -&gt; STM (TVar Natural)
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036822"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-89"></span><span>  </span><span class="annot"><span class="annottext">TBQueue a -&gt; STM (TBQueue a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar Natural
-&gt; TVar [a] -&gt; TVar Natural -&gt; TVar [a] -&gt; Natural -&gt; TBQueue a
forall a.
TVar Natural
-&gt; TVar [a] -&gt; TVar Natural -&gt; TVar [a] -&gt; Natural -&gt; TBQueue a
</span><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-var">TBQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036819"><span class="hs-identifier hs-var">rsize</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036821"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036818"><span class="hs-identifier hs-var">wsize</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036820"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036822"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-90"></span><span>
</span><span id="line-91"></span><span class="hs-comment">-- |@IO@ version of 'newTBQueue'.  This is useful for creating top-level</span><span>
</span><span id="line-92"></span><span class="hs-comment">-- 'TBQueue's using 'System.IO.Unsafe.unsafePerformIO', because using</span><span>
</span><span id="line-93"></span><span class="hs-comment">-- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't</span><span>
</span><span id="line-94"></span><span class="hs-comment">-- possible.</span><span>
</span><span id="line-95"></span><span id="local-6989586621679036896"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#newTBQueueIO"><span class="hs-identifier hs-type">newTBQueueIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Natural</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036896"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-96"></span><span id="newTBQueueIO"><span class="annot"><span class="annottext">newTBQueueIO :: forall a. Natural -&gt; IO (TBQueue a)
</span><a href="Control.Concurrent.STM.TBQueue.html#newTBQueueIO"><span class="hs-identifier hs-var hs-var">newTBQueueIO</span></a></span></span><span> </span><span id="local-6989586621679036810"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036810"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-97"></span><span>  </span><span id="local-6989586621679036809"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036809"><span class="hs-identifier hs-var">read</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; IO (TVar [a])
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-98"></span><span>  </span><span id="local-6989586621679036808"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036808"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; IO (TVar [a])
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-99"></span><span>  </span><span id="local-6989586621679036807"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036807"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Natural -&gt; IO (TVar Natural)
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span>
</span><span id="line-100"></span><span>  </span><span id="local-6989586621679036806"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036806"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Natural -&gt; IO (TVar Natural)
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036810"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-101"></span><span>  </span><span class="annot"><span class="annottext">TBQueue a -&gt; IO (TBQueue a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar Natural
-&gt; TVar [a] -&gt; TVar Natural -&gt; TVar [a] -&gt; Natural -&gt; TBQueue a
forall a.
TVar Natural
-&gt; TVar [a] -&gt; TVar Natural -&gt; TVar [a] -&gt; Natural -&gt; TBQueue a
</span><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-var">TBQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036807"><span class="hs-identifier hs-var">rsize</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036809"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036806"><span class="hs-identifier hs-var">wsize</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036808"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036810"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-102"></span><span>
</span><span id="line-103"></span><span class="hs-comment">-- |Write a value to a 'TBQueue'; blocks if the queue is full.</span><span>
</span><span id="line-104"></span><span id="local-6989586621679036893"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#writeTBQueue"><span class="hs-identifier hs-type">writeTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036893"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679036893"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-105"></span><span id="writeTBQueue"><span class="annot"><span class="annottext">writeTBQueue :: forall a. TBQueue a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TBQueue.html#writeTBQueue"><span class="hs-identifier hs-var hs-var">writeTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036790"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036790"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span id="local-6989586621679036789"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036789"><span class="hs-identifier hs-var">_read</span></a></span></span><span> </span><span id="local-6989586621679036788"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036788"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span id="local-6989586621679036787"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036787"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span id="local-6989586621679036786"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036786"><span class="hs-identifier hs-var">_size</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679036785"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036785"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-106"></span><span>  </span><span id="local-6989586621679036784"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036784"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036788"><span class="hs-identifier hs-var">wsize</span></a></span><span>
</span><span id="line-107"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036784"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-108"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036788"><span class="hs-identifier hs-var">wsize</span></a></span><span> </span><span class="annot"><span class="annottext">(Natural -&gt; STM ()) -&gt; Natural -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036784"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">1</span></span><span>
</span><span id="line-109"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-110"></span><span>          </span><span id="local-6989586621679036781"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036781"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036790"><span class="hs-identifier hs-var">rsize</span></a></span><span>
</span><span id="line-111"></span><span>          </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036781"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-112"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036790"><span class="hs-identifier hs-var">rsize</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span>
</span><span id="line-113"></span><span>                     </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036788"><span class="hs-identifier hs-var">wsize</span></a></span><span> </span><span class="annot"><span class="annottext">(Natural -&gt; STM ()) -&gt; Natural -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036781"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">1</span></span><span>
</span><span id="line-114"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">STM ()
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-115"></span><span>  </span><span id="local-6989586621679036780"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036780"><span class="hs-identifier hs-var">listend</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036787"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-116"></span><span>  </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036787"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036785"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036780"><span class="hs-identifier hs-var">listend</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-117"></span><span>
</span><span id="line-118"></span><span class="hs-comment">-- |Read the next value from the 'TBQueue'.</span><span>
</span><span id="line-119"></span><span id="local-6989586621679036883"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#readTBQueue"><span class="hs-identifier hs-type">readTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036883"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036883"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-120"></span><span id="readTBQueue"><span class="annot"><span class="annottext">readTBQueue :: forall a. TBQueue a -&gt; STM a
</span><a href="Control.Concurrent.STM.TBQueue.html#readTBQueue"><span class="hs-identifier hs-var hs-var">readTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036768"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036768"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span id="local-6989586621679036767"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036767"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679036766"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036766"><span class="hs-identifier hs-var">_wsize</span></a></span></span><span> </span><span id="local-6989586621679036765"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036765"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span id="local-6989586621679036764"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036764"><span class="hs-identifier hs-var">_size</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-121"></span><span>  </span><span id="local-6989586621679036763"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036763"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036767"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-122"></span><span>  </span><span id="local-6989586621679036762"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036762"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036768"><span class="hs-identifier hs-var">rsize</span></a></span><span>
</span><span id="line-123"></span><span>  </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036768"><span class="hs-identifier hs-var">rsize</span></a></span><span> </span><span class="annot"><span class="annottext">(Natural -&gt; STM ()) -&gt; Natural -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036762"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">1</span></span><span>
</span><span id="line-124"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036763"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-125"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679036760"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036760"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679036759"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036759"><span class="hs-identifier hs-var">xs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-126"></span><span>      </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036767"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036759"><span class="hs-identifier hs-var">xs'</span></a></span><span>
</span><span id="line-127"></span><span>      </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036760"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-128"></span><span>    </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-129"></span><span>      </span><span id="local-6989586621679036758"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036758"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036765"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-130"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036758"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-131"></span><span>        </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-132"></span><span>        </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-133"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679036757"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036757"><span class="hs-identifier hs-var">z</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679036756"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036756"><span class="hs-identifier hs-var">zs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036758"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-comment">-- NB. lazy: we want the transaction to be</span><span>
</span><span id="line-134"></span><span>                                  </span><span class="hs-comment">-- short, otherwise it will conflict</span><span>
</span><span id="line-135"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036765"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-136"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036767"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036756"><span class="hs-identifier hs-var">zs</span></a></span><span>
</span><span id="line-137"></span><span>          </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036757"><span class="hs-identifier hs-var">z</span></a></span><span>
</span><span id="line-138"></span><span>
</span><span id="line-139"></span><span class="hs-comment">-- | A version of 'readTBQueue' which does not retry. Instead it</span><span>
</span><span id="line-140"></span><span class="hs-comment">-- returns @Nothing@ if no value is available.</span><span>
</span><span id="line-141"></span><span id="local-6989586621679036880"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#tryReadTBQueue"><span class="hs-identifier hs-type">tryReadTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036880"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036880"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-142"></span><span id="tryReadTBQueue"><span class="annot"><span class="annottext">tryReadTBQueue :: forall a. TBQueue a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TBQueue.html#tryReadTBQueue"><span class="hs-identifier hs-var hs-var">tryReadTBQueue</span></a></span></span><span> </span><span id="local-6989586621679036751"><span class="annot"><span class="annottext">TBQueue a
</span><a href="#local-6989586621679036751"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe a) -&gt; STM a -&gt; STM (Maybe a)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TBQueue a -&gt; STM a
forall a. TBQueue a -&gt; STM a
</span><a href="Control.Concurrent.STM.TBQueue.html#readTBQueue"><span class="hs-identifier hs-var">readTBQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TBQueue a
</span><a href="#local-6989586621679036751"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">STM (Maybe a) -&gt; STM (Maybe a) -&gt; STM (Maybe a)
forall a. STM a -&gt; STM a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#orElse"><span class="hs-operator hs-var">`orElse`</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-143"></span><span>
</span><span id="line-144"></span><span class="hs-comment">-- | Efficiently read the entire contents of a 'TBQueue' into a list. This</span><span>
</span><span id="line-145"></span><span class="hs-comment">-- function never retries.</span><span>
</span><span id="line-146"></span><span class="hs-comment">--</span><span>
</span><span id="line-147"></span><span class="hs-comment">-- @since 2.4.5</span><span>
</span><span id="line-148"></span><span id="local-6989586621679036874"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#flushTBQueue"><span class="hs-identifier hs-type">flushTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036874"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679036874"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-149"></span><span id="flushTBQueue"><span class="annot"><span class="annottext">flushTBQueue :: forall a. TBQueue a -&gt; STM [a]
</span><a href="Control.Concurrent.STM.TBQueue.html#flushTBQueue"><span class="hs-identifier hs-var hs-var">flushTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036738"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036738"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span id="local-6989586621679036737"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036737"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679036736"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036736"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span id="local-6989586621679036735"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036735"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span id="local-6989586621679036734"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036734"><span class="hs-identifier hs-var">size</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-150"></span><span>  </span><span id="local-6989586621679036733"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036733"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036737"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-151"></span><span>  </span><span id="local-6989586621679036732"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036732"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036735"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-152"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036733"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036732"><span class="hs-identifier hs-var">ys</span></a></span><span>
</span><span id="line-153"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; STM [a]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-154"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-155"></span><span>      </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036737"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-156"></span><span>      </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036735"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-157"></span><span>      </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036738"><span class="hs-identifier hs-var">rsize</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span>
</span><span id="line-158"></span><span>      </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036736"><span class="hs-identifier hs-var">wsize</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036734"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-159"></span><span>      </span><span class="annot"><span class="annottext">[a] -&gt; STM [a]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036733"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a] -&gt; [a]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036732"><span class="hs-identifier hs-var">ys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-160"></span><span>
</span><span id="line-161"></span><span class="hs-comment">-- | Get the next value from the @TBQueue@ without removing it,</span><span>
</span><span id="line-162"></span><span class="hs-comment">-- retrying if the channel is empty.</span><span>
</span><span id="line-163"></span><span id="local-6989586621679036729"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#peekTBQueue"><span class="hs-identifier hs-type">peekTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036729"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036729"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-164"></span><span id="peekTBQueue"><span class="annot"><span class="annottext">peekTBQueue :: forall a. TBQueue a -&gt; STM a
</span><a href="Control.Concurrent.STM.TBQueue.html#peekTBQueue"><span class="hs-identifier hs-var hs-var">peekTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679036722"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036722"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679036721"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036721"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-165"></span><span>  </span><span id="local-6989586621679036720"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036720"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036722"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-166"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036720"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-167"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679036719"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036719"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036719"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-168"></span><span>    </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-169"></span><span>      </span><span id="local-6989586621679036718"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036718"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036721"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-170"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036718"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-171"></span><span>        </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-172"></span><span>        </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-173"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679036717"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036717"><span class="hs-identifier hs-var">z</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679036716"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036716"><span class="hs-identifier hs-var">zs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036718"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-comment">-- NB. lazy: we want the transaction to be</span><span>
</span><span id="line-174"></span><span>                                  </span><span class="hs-comment">-- short, otherwise it will conflict</span><span>
</span><span id="line-175"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036721"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-176"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036722"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036717"><span class="hs-identifier hs-var">z</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036716"><span class="hs-identifier hs-var">zs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>          </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036717"><span class="hs-identifier hs-var">z</span></a></span><span>
</span><span id="line-178"></span><span>
</span><span id="line-179"></span><span class="hs-comment">-- | A version of 'peekTBQueue' which does not retry. Instead it</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- returns @Nothing@ if no value is available.</span><span>
</span><span id="line-181"></span><span id="local-6989586621679036715"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#tryPeekTBQueue"><span class="hs-identifier hs-type">tryPeekTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036715"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036715"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-182"></span><span id="tryPeekTBQueue"><span class="annot"><span class="annottext">tryPeekTBQueue :: forall a. TBQueue a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TBQueue.html#tryPeekTBQueue"><span class="hs-identifier hs-var hs-var">tryPeekTBQueue</span></a></span></span><span> </span><span id="local-6989586621679036710"><span class="annot"><span class="annottext">TBQueue a
</span><a href="#local-6989586621679036710"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-183"></span><span>  </span><span id="local-6989586621679036709"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679036709"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TBQueue a -&gt; STM (Maybe a)
forall a. TBQueue a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TBQueue.html#tryReadTBQueue"><span class="hs-identifier hs-var">tryReadTBQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TBQueue a
</span><a href="#local-6989586621679036710"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-184"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679036709"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-185"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-186"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679036708"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036708"><span class="hs-identifier hs-var">x</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-187"></span><span>      </span><span class="annot"><span class="annottext">TBQueue a -&gt; a -&gt; STM ()
forall a. TBQueue a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TBQueue.html#unGetTBQueue"><span class="hs-identifier hs-var">unGetTBQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TBQueue a
</span><a href="#local-6989586621679036710"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036708"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-188"></span><span>      </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679036709"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="hs-comment">-- |Put a data item back onto a channel, where it will be the next item read.</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- Blocks if the queue is full.</span><span>
</span><span id="line-192"></span><span id="local-6989586621679036707"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#unGetTBQueue"><span class="hs-identifier hs-type">unGetTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036707"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679036707"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-193"></span><span id="unGetTBQueue"><span class="annot"><span class="annottext">unGetTBQueue :: forall a. TBQueue a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TBQueue.html#unGetTBQueue"><span class="hs-identifier hs-var hs-var">unGetTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036694"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036694"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span id="local-6989586621679036693"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036693"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679036692"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036692"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span id="local-6989586621679036691"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036691"><span class="hs-identifier hs-var">_write</span></a></span></span><span> </span><span id="local-6989586621679036690"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036690"><span class="hs-identifier hs-var">_size</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679036689"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036689"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-194"></span><span>  </span><span id="local-6989586621679036688"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036688"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036694"><span class="hs-identifier hs-var">rsize</span></a></span><span>
</span><span id="line-195"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036688"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-196"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036694"><span class="hs-identifier hs-var">rsize</span></a></span><span> </span><span class="annot"><span class="annottext">(Natural -&gt; STM ()) -&gt; Natural -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036688"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">1</span></span><span>
</span><span id="line-197"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-198"></span><span>          </span><span id="local-6989586621679036687"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036687"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036692"><span class="hs-identifier hs-var">wsize</span></a></span><span>
</span><span id="line-199"></span><span>          </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036687"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-200"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; Natural -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036692"><span class="hs-identifier hs-var">wsize</span></a></span><span> </span><span class="annot"><span class="annottext">(Natural -&gt; STM ()) -&gt; Natural -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036687"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">1</span></span><span>
</span><span id="line-201"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">STM ()
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-202"></span><span>  </span><span id="local-6989586621679036686"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036686"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036693"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-203"></span><span>  </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036693"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679036689"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036686"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span class="hs-comment">-- |Return the length of a 'TBQueue'.</span><span>
</span><span id="line-206"></span><span class="hs-comment">--</span><span>
</span><span id="line-207"></span><span class="hs-comment">-- @since 2.5.0.0</span><span>
</span><span id="line-208"></span><span id="local-6989586621679036866"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#lengthTBQueue"><span class="hs-identifier hs-type">lengthTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036866"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Natural</span></span></span><span>
</span><span id="line-209"></span><span id="lengthTBQueue"><span class="annot"><span class="annottext">lengthTBQueue :: forall a. TBQueue a -&gt; STM Natural
</span><a href="Control.Concurrent.STM.TBQueue.html#lengthTBQueue"><span class="hs-identifier hs-var hs-var">lengthTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036680"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036680"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span id="local-6989586621679036679"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036679"><span class="hs-identifier hs-var">_read</span></a></span></span><span> </span><span id="local-6989586621679036678"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036678"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span id="local-6989586621679036677"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036677"><span class="hs-identifier hs-var">_write</span></a></span></span><span> </span><span id="local-6989586621679036676"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036676"><span class="hs-identifier hs-var">size</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-210"></span><span>  </span><span id="local-6989586621679036675"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036675"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036680"><span class="hs-identifier hs-var">rsize</span></a></span><span>
</span><span id="line-211"></span><span>  </span><span id="local-6989586621679036674"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036674"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036678"><span class="hs-identifier hs-var">wsize</span></a></span><span>
</span><span id="line-212"></span><span>  </span><span class="annot"><span class="annottext">Natural -&gt; STM Natural
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Natural -&gt; STM Natural) -&gt; Natural -&gt; STM Natural
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036676"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036675"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Natural
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036674"><span class="hs-identifier hs-var">w</span></a></span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span class="hs-comment">-- |Returns 'True' if the supplied 'TBQueue' is empty.</span><span>
</span><span id="line-215"></span><span id="local-6989586621679036864"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#isEmptyTBQueue"><span class="hs-identifier hs-type">isEmptyTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036864"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span><span>
</span><span id="line-216"></span><span id="isEmptyTBQueue"><span class="annot"><span class="annottext">isEmptyTBQueue :: forall a. TBQueue a -&gt; STM Bool
</span><a href="Control.Concurrent.STM.TBQueue.html#isEmptyTBQueue"><span class="hs-identifier hs-var hs-var">isEmptyTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036668"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036668"><span class="hs-identifier hs-var">_rsize</span></a></span></span><span> </span><span id="local-6989586621679036667"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036667"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679036666"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036666"><span class="hs-identifier hs-var">_wsize</span></a></span></span><span> </span><span id="local-6989586621679036665"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036665"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span id="local-6989586621679036664"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036664"><span class="hs-identifier hs-var">_size</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-217"></span><span>  </span><span id="local-6989586621679036663"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036663"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036667"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-218"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036663"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-219"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-220"></span><span>    </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679036662"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036662"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036665"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-221"></span><span>             </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679036662"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-222"></span><span>               </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-223"></span><span>               </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-224"></span><span>
</span><span id="line-225"></span><span class="hs-comment">-- |Returns 'True' if the supplied 'TBQueue' is full.</span><span>
</span><span id="line-226"></span><span class="hs-comment">--</span><span>
</span><span id="line-227"></span><span class="hs-comment">-- @since 2.4.3</span><span>
</span><span id="line-228"></span><span id="local-6989586621679036661"><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#isFullTBQueue"><span class="hs-identifier hs-type">isFullTBQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679036661"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span><span>
</span><span id="line-229"></span><span id="isFullTBQueue"><span class="annot"><span class="annottext">isFullTBQueue :: forall a. TBQueue a -&gt; STM Bool
</span><a href="Control.Concurrent.STM.TBQueue.html#isFullTBQueue"><span class="hs-identifier hs-var hs-var">isFullTBQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TBQueue.html#TBQueue"><span class="hs-identifier hs-type">TBQueue</span></a></span><span> </span><span id="local-6989586621679036651"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036651"><span class="hs-identifier hs-var">rsize</span></a></span></span><span> </span><span id="local-6989586621679036650"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036650"><span class="hs-identifier hs-var">_read</span></a></span></span><span> </span><span id="local-6989586621679036649"><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036649"><span class="hs-identifier hs-var">wsize</span></a></span></span><span> </span><span id="local-6989586621679036648"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679036648"><span class="hs-identifier hs-var">_write</span></a></span></span><span> </span><span id="local-6989586621679036647"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036647"><span class="hs-identifier hs-var">_size</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-230"></span><span>  </span><span id="local-6989586621679036646"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036646"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036649"><span class="hs-identifier hs-var">wsize</span></a></span><span>
</span><span id="line-231"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036646"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-232"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-233"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-234"></span><span>         </span><span id="local-6989586621679036645"><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036645"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Natural -&gt; STM Natural
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Natural
</span><a href="#local-6989586621679036651"><span class="hs-identifier hs-var">rsize</span></a></span><span>
</span><span id="line-235"></span><span>         </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Natural
</span><a href="#local-6989586621679036645"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Natural -&gt; Natural -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Natural
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-236"></span><span>            </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-237"></span><span>            </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-238"></span></pre></body></html>